//
//  HomeRootViewModel.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/12/6.
//

#import "HomeRootViewModel.h"

@implementation HomeRootViewModel

- (void)fetchHome:(void(^)(void))block
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSArray *array = [NSArray arrayWithArray:[LocalData getMenudicWithKey:@"home_section"]];
        self.homeSections = [HomeRootModel mj_objectArrayWithKeyValuesArray:array];
        self.homeTopDetailModel = [GameDetailNewModel mj_objectWithKeyValues:[LocalData getMenudicWithKey:@"home_top_gamedetail"]];
        
        [[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:self.homeTopDetailModel.gameMainIcon] options:YYWebImageOptionProgressive progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            
        } transform:^UIImage * _Nullable(UIImage * _Nonnull image, NSURL * _Nonnull url) {
            return image;
        } completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
            [UIImage getSubjectColor:^(UIColor * _Nonnull color) {
                self.topBgColor = color;
                block();
            } withImage:image];
        }];
        
    });
}

@end
